package com.atguigu.jxc.service.impl;

import com.atguigu.jxc.dao.OverflowListGoodsMapper;
import com.atguigu.jxc.entity.OverflowList;
import com.atguigu.jxc.entity.OverflowListGoods;
import com.atguigu.jxc.service.OverflowListGoodsService;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OverflowListGoodsServiceimpl implements OverflowListGoodsService {

    @Autowired
    OverflowListGoodsMapper overflowListGoodsMapper;

    @Override
    //新增报溢单
    public void save(OverflowList overflowList, String overflowListGoodsStr) {
        //转成集合
        Gson gson=new Gson();
       List<OverflowListGoods>  overflowListGoods = gson.fromJson(overflowListGoodsStr, new TypeToken<List<OverflowListGoods>>() {
        }.getType());

             //给操作的用户赋值
            overflowList.setUserId(1);
            //进行保存
       overflowListGoodsMapper.saveoverflowList(overflowList);
        System.out.println(overflowList.getOverflowListId());

        for (OverflowListGoods overflowListGood : overflowListGoods) {
                overflowListGood.setOverflowListId(overflowList.getOverflowListId());
                //进行保存
               overflowListGoodsMapper.saveoverflowListGoodsStr(overflowListGood);
        }




    }

    //报溢单查询
    @Override
    public List<OverflowList> list(String sTime, String eTime) {
           return    overflowListGoodsMapper.list(sTime,eTime);
    }

    //报溢单商品信息
    @Override
    public List<OverflowListGoods> goodsList(Integer overflowListId) {
        return overflowListGoodsMapper.goodsList(overflowListId);
    }
}
